package com.weigang.webservice.service.impl;

import com.weigang.webservice.dto.User;
import com.weigang.webservice.service.UserAuthInterceptorServer;
import org.springframework.stereotype.Component;

import javax.jws.WebService;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@WebService(
        targetNamespace = "http://service.webservice.weigang.com/",
        endpointInterface = "com.weigang.webservice.service.UserAuthInterceptorServer"
)
@Component
public class UserAuthInterceptorServerImpl implements UserAuthInterceptorServer {

    public User queryUserAuthInterceptor(String id, String name) {
        System.out.println("queryUser参数id ===>" + id);
        System.out.println("queryUser参数name ===>" + name);
        List<User> list = new ArrayList();
        list.add(new User("1", "张三", "21"));
        list.add(new User("2", "李四", "25"));
        List<String> idList = list.stream().map(User::getId).collect(Collectors.toList());
        List<String> nameList = list.stream().map(User::getName).collect(Collectors.toList());
        for (User user : list) {
            if (id != null && idList.contains(id)) {
                System.out.println(id.equals(user.getId()));
                if (id.equals(user.getId())) {
                    return user;
                }
            } else if (name != null && nameList.contains(name)) {
                if (name.equals(user.getName())) {
                    return user;
                }
            } else if (id != null && name != null) {
                return new User(id, name, "24");
            }
        }
        return new User("3", "王武", "225");
    }
}
